<?xml version="1.0" encoding="utf-8" ?>
<!-- this is a stylesheet for converting 
	 process definition into dot.exe graph description file.
	 It is used for generating process graphical representation.
-->
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns="http://www.nginn.org/WorkflowDefinition.1_0.xsd" 
    xmlns:ng="http://www.nginn.org/WorkflowDefinition.1_0.xsd"
    xmlns:str="http://exslt.org/strings"
    extension-element-prefixes="str">
	
    <xsl:output method="text" indent="yes" />
	<xsl:template match="/">
		<xsl:apply-templates select="ng:process" />
	</xsl:template>
	
	<xsl:template match="ng:process">
		graph: {
			manhattan_edges: yes
			display_edge_labels: yes
			outport_sharing: yes
			inport_sharing: yes
			arrow_mode: fixed
			<xsl:apply-templates select="ng:body" />
		}
	</xsl:template>
	
	<xsl:template match="ng:body">
		<xsl:apply-templates select="ng:places" />
		<xsl:apply-templates select="ng:tasks" />
		<xsl:apply-templates select="ng:flows" />
	</xsl:template>
	
	<xsl:template match="ng:places">
		<xsl:apply-templates select="*" />
	</xsl:template>
	<xsl:template match="ng:tasks">
		<xsl:apply-templates select="*" />
	</xsl:template>
	<xsl:template match="ng:flows">
		<xsl:apply-templates select="*" />
	</xsl:template>
	
	<xsl:template match="ng:place">
		node: { 
			title: &quot;<xsl:value-of select='@id' />&quot; 
			shape: circle
			width: 50 
			height: 50
			<xsl:if test="@label">label: "<xsl:value-of select='@label' />"</xsl:if>
		}
	</xsl:template>
	
	
	
	<xsl:template match="ng:task">
		node: { 
			title: &quot;<xsl:value-of select='@id' />&quot; 
			height: 60
			<xsl:if test="@label">label: "<xsl:value-of select='@label' />"</xsl:if>
		}
	</xsl:template>
	
	<xsl:template match="ng:composite">
		graph: { 
			title: &quot;<xsl:value-of select='@id' />&quot; 
			<xsl:if test="@label">label: "<xsl:value-of select='@label' />"</xsl:if>
			status: boxed
			margin: 10
			<xsl:apply-templates select="ng:body" />
		}
	</xsl:template>
	
	<xsl:template match="ng:flow">
		<xsl:variable name="fromid" select="@from" />
		<xsl:variable name="toid" select="@to" />
		<xsl:variable name="fromnode" select="//ng:*[@id=$fromid]" />
		<xsl:variable name="tonode" select="//ng:*[@id=$toid]" />
		edge: { 
			backarrowsize: 10
			<xsl:choose>
				<xsl:when test="$fromnode/@splitType = 'XOR'">backarrowstyle: none</xsl:when>
				<xsl:when test="$fromnode/@splitType = 'OR'">backarrowstyle: none</xsl:when>
				<xsl:otherwise>backarrowstyle: none</xsl:otherwise>
			</xsl:choose>
			source:&quot;<xsl:value-of select='@from' />&quot; target:"<xsl:value-of select='@to' />"
			<xsl:choose>
				<xsl:when test="$tonode/@joinType = 'XOR'">arrowstyle: solid</xsl:when>
				<xsl:when test="$tonode/@joinType = 'OR'">arrowstyle: solid</xsl:when>
				<xsl:otherwise>arrowstyle: solid</xsl:otherwise>
			</xsl:choose>
		}
	</xsl:template>

</xsl:stylesheet>